package cc.fs.study.smart_app;

import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.File;

import cc.fs.study.R;

/**
 * 增量更新 示例
 */
public class SmartUpdateActivity extends AppCompatActivity{

    TextView vision;
    Button btn;
    SmartUpdate smartUpdate;
    String patchPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "StudyPatch" + File.separator+"2to1.patch";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_smart_update);

        vision = (TextView)findViewById(R.id.textview1);
        btn = (Button)findViewById(R.id.btn);
        vision.setText("版本1.0");

        smartUpdate = new SmartUpdate(new SmartUpdate.SmartCallback() {
            @Override
            public void onSuccess(String newApkPath) {
                Log.e("增量更新成功",newApkPath);
            }

            @Override
            public void onFail() {
                Log.e("增量更新失败","");
            }
        });

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                smartUpdate.start(ApkUtils.getSourceApkPath(getApplicationContext()),patchPath);
            }
        });
    }


}
